package com.yjkf.zh.admin.service.impl;

import com.yjkf.zh.admin.dao.SysDeviceEventMapper;
import com.yjkf.zh.admin.model.SysDeviceEvent;
import com.yjkf.zh.admin.service.SysDeviceEventService;
import com.yjkf.zh.core.page.MyPageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysDeviceEventServiceImpl implements SysDeviceEventService {

    @Autowired
    private SysDeviceEventMapper sysDeviceEventMapper;
    @Override
    public MyPageResult<SysDeviceEvent> findDeviceEventPage(int pageNum, int pageSize) {
/*        Map<String,Object> data = new HashMap<>();
        data.put("pageNum",(pageNum-1)*pageSize);
        data.put("pageSize",pageSize);*/
        int start = (pageNum-1)*pageSize;

        List<SysDeviceEvent> list= sysDeviceEventMapper.findDeviceEventPage(start,pageSize);
        MyPageResult<SysDeviceEvent> myPageResult = new MyPageResult<>();
        int count = sysDeviceEventMapper.deviceEventCount().getCount();
        System.out.println(count);
        myPageResult.setPageSize(pageSize);
        myPageResult.setContent(list);
        myPageResult.setTotalSize(count);
        return myPageResult;
    }

    @Override
    public List<SysDeviceEvent> findDeviceEventForIdentName(String identName) {

        return sysDeviceEventMapper.findDeviceEventForIdentName(identName);
    }

    @Override
    public int saveDeviceEvent(SysDeviceEvent sysDeviceEvent) {
        return sysDeviceEventMapper.saveDeviceEvent(sysDeviceEvent);
    }
}
